package homework.test02;

import java.io.File;
import java.util.Scanner;

public class demo03 {
    static boolean flag = false;
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个路径：");
        String str = sc.nextLine();
        System.out.println("请输入要查找的文件名称：");
        String f = sc.nextLine();
        File d = new File(str);

        if(!(findFile(d, f))){
            System.out.println("没有找到该文件");
        }
    }

    public static boolean findFile(File d, String f) {

        File[] files = d.listFiles();
        for (File file : files) {
            if (file.isFile()) {
                if (file.getName().equals(f)) {
                    System.out.printf(file.getAbsolutePath());
                    System.out.println(file.length() +"字节");
                    flag = true;
                }
            } else {
                findFile(file, f);
            }
        }
        return flag;
    }
}
